package mahjong.auto.com.os;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.io.InputStream;

import mahjong.auto.com.automahjong.App;

/**
 * Created by heqian on 17-8-2.
 */

public class Mahjong {
    static {
        System.loadLibrary("native-lib");
    }

    private static MahjongCall call = null;

    public static native void init();

    public static native void destroy();

    public static native void discern(Bitmap bitmap);

    public static void setCall(MahjongCall call) {
        Mahjong.call = call;
    }

    public static native void test(Bitmap bitmap);

    private static Bitmap loadBitmap(String path) {
        try {
            InputStream is = App.getApp().getResources().getAssets().open(path);
            Drawable drawable = Drawable.createFromStream(is, null);
            is.close();
            return ((BitmapDrawable) drawable).getBitmap();

        } catch (Exception e) {
            return null;
        }
    }

    private static boolean simulateClick(int x, int y) {
        if (null != call)
            return call.simulateClick(x, y);
        return false;
    }

    private static void info(BoardInfo info) {
        if (null != call)
            call.info(info);
    }

    public interface MahjongCall {
        boolean simulateClick(int x, int y);

        void info(BoardInfo info);
    }
}
